#!/bin/bash

#input dao channel shang yi ceng
imagePath=$1 #dao append
detPath=$2
outPutPath=$3
faceOutPath=$4

resultfile="////"

faceNum=7
client_1=root@10.255.130.150
client_2=root@10.255.130.147
all_num=`ls -l "$detPath"|grep "^d"|wc -l`
echo 'detPath' $detPath

#/data/ossfs/liu/deep_track/deep_track_app_face.py;--image_dir;${imageDir};--detection_dir;${combineKey:replace(${imageDirName},'featureOutput')}/Append;--max_cosine_distance;0.2;--min_confidence;0.3;--nn_budget;100;--output_file;${combineKey:replace(${imageDirName},${trackOutDirName})}_track.txt;--face_dir;${combineKey:replace(${imageDirName},${faceOutDirName})}

#/data/ossfs/liu/deep_track/deep_track_app_new.py;--max_cosine_distance;0.2;--min_confidence;0.3;--nn_budget;100;--detection_dir;${combineKey:replace(${imageDirName},'featureOutput')}/Append;--output_file;${combineKey:replace(${imageDirName},${trackOutDirName})}_track.txt


echo $args
echo $all_num
echo $1

function makeArgs()
{
	args="/data/yanguolong/program/deep_track/deep_track_app_new.py --max_cosine_distance 0.2 --min_confidence 0.3 --nn_budget 100 --detection_dir $detPath/Channel_0$1/Append --output_file $outPutPath/Channel_0${1}_track.txt"
	echo $args
	#return $args;
 }


#rizhi chongdingxiang
# "> trackLog_Channel0${num} 2>&1"
function makeFaceArgs()
{
	args="/data/yanguolong/program/deep_track/deep_track_app_new.py --max_cosine_distance 0.2 --min_confidence 0.3 --nn_budget 100 --image_dir $imagePath --detection_dir $detPath/Channel_0$1/Append --output_file $outPutPath/Channel_0${1}_track.txt --face_dir $faceOutPath"
	echo $args
	#return $args;
 }

for num in `seq 1 ${all_num}`
do
{
	if [ $num -eq $faceNum ];then
    echo ${num}
	commend=$(makeFaceArgs "${num}")
	python $commend > trackLog_Channel0${num} 2>&1
 
	elif [ $num -le 3 ];then
		commend=$(makeArgs "${num}") 
		result=`ssh $client_1 > trackLog_Channel0${num} 2>&1 python $commend`
		echo 'result ' ${result}
		#commend=$(makeArgs "${num}")
		#ssh $client_1 python $commend
		#echo "ssh $client_1 "python $commend""
		echo ${num}
		echo 'client_1'
	elif [ $num -lt  $faceNum ];then
		commend=$(makeArgs "${num}")
		ssh $client_2 "python $commend > trackLog_Channel0${num} 2>&1"
		echo 'client_2'
	else 
		commend=$(makeArgs "${num}")
		python $commend > trackLog_Channel0${num} 2>&1
		echo 'other' + ${num} 
	fi
} &
done

wait
count=0
cat resultfile | while read line
do
	let count+=1
done
if [ $count -ne 8 ];then
	exit 1
else 
	exit 0
fi


